package com.riven.bilibilidemo.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.riven.bilibilidemo.R;
import com.riven.bilibilidemo.bean.BangumiBean;

/**
 * Created by Pooh on 2017/3/10.
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHodler>{
    private BangumiBean bean;
    Context context;
    public MyAdapter(Context context,BangumiBean bean) {
        this.context = context;
        this.bean=bean;
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.recycler_first,parent,false);
        ViewHodler hodler = new ViewHodler(view);
        return hodler;
    }

    @Override
    public void onBindViewHolder(ViewHodler holder, int position) {
        if (position==1){
            holder.recycle_first_name.setText("十月新番");
            holder.recycle_first_lianzai.setText("分季列表");
            holder.recycle_first_img.setImageResource(R.drawable.bangumi_home_ic_season_4);
        }
        //解决ScollView嵌套RecyclerView界面卡顿问题
        holder.recycle_first_item.setLayoutManager(new GridLayoutManager(context,3){
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        MyFristAdater myFristAdater = new MyFristAdater(context,bean,position);
        holder.recycle_first_item.setAdapter(myFristAdater);
    }

    @Override
    public int getItemCount() {
        return 2;
    }
    public class ViewHodler extends RecyclerView.ViewHolder {

        private final RecyclerView recycle_first_item;
        private final ImageView recycle_first_img;
        private final TextView recycle_first_name;
        private final TextView recycle_first_lianzai;

        public ViewHodler(View itemView) {
            super(itemView);
            recycle_first_img = (ImageView) itemView.findViewById(R.id.recycle_first_img);
            recycle_first_name = (TextView) itemView.findViewById(R.id.recycle_first_name);
            recycle_first_lianzai = (TextView) itemView.findViewById(R.id.recycle_first_lianzai);
            recycle_first_item = (RecyclerView) itemView.findViewById(R.id.recycle_first_item);
        }
    }
}
